import java.util.Scanner;

public class Palindrome {

	/**
	 * Return number palindrom number between start - end
	 * @param start
	 * @param end
	 * @return
	 */
	private static int numberPalindrom(final int start, final int end) {
		// Validation
		int number = 0;
		// one more thing i 've just read is limited the return command :D
		// If start > end => what the fuck is that?, error -1
		if (start > end) {
			number = -1; // Error, gruhh
		} else {
			// Loop in this range and check every number
			for (int i = start; i < end; i++) {
				// Well then, if match, increasing them :D
				if (checkPalindrom(i)) {
					number = number + 1;
				}
			}
		}
		// That is it
		return number;

	}

	/**
	 * Check a number is palindrom or not
	 * @param number
	 * @return
	 */
	private static boolean checkPalindrom(int number) {
		// < 10, return
		if (number < 10)
			return false;
		// Ok, now we will separate each digit of this number
		// ex: 1211 => 1 2 1 1
		// An easy solution is using String.toArray ;)
		String numberString = String.valueOf(number);
		char[] numberChar = numberString.toCharArray();
		// Ok , just check this
		final int length = numberChar.length;
		// Because we just care about from 0 - midle -1 and remain
		// Do not matter 
		// EG: 22 -> length 2
		for (int i = 0; i < (length / 2); i++) {
			// If got one case that does not match, false
			if (numberChar[i] != numberChar[length - 1 - i]) {
				return false;
			}
		}
		return true;
	}

	// Main our program
	// Read from command line
	public static void main(String[] args) {
		// Sample Password 
		Scanner input = new Scanner(System.in);
		// Number of case
		int N = input.nextInt();
		input.nextLine();// skip enter
		// Ok, create array of case, 2 dimensions
		int[][] casePalindrom = new int[N][2];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 2; j++) {
				casePalindrom[i][j] = input.nextInt();
			}
			input.nextLine();// skip enter
		}
		// Close stream
		input.close();
		// Process our job
		// Loop over these array ;) and call our function
		for (int i = 0; i < N; i++) {
			System.out.println(numberPalindrom(casePalindrom[i][0], casePalindrom[i][1]));
		}
	}
}
